import { Devices } from '@/entries/index'
import { logger } from '@/utils/util'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    productList: ['A666G', 'DL1', 'DL2', 'DX1', 'G777G', 'T808', 'TZ1', 'X2A', 'X1', 'X5', '302G', 'YE620AR'],
    pdfUrl: null,
    pdfShow: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const { productList } = this.data;
    let list = productList.map(item => {
        return Devices[item]
    })
    this.setData({
        productList: list
    })
  },
  onTapItem(e) {
    wx.downloadFile({
        // 示例 url，并非真实存在
        url: Devices[e.currentTarget.dataset.item.productType].pdfUrl,
        success: function (res) {
          const filePath = res.tempFilePath
          wx.openDocument({
            filePath: filePath,
            success: function (res) {
              logger.log('打开文档成功')
            }
          })
        }
      })
  },
})